package org.idea.spring.dependency.inject.constructor;

import org.idea.spring.dependency.inject.setter.PersonHolder;
import org.idea.spring.ioc.bean.Person;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @Author linhao
 * @Date created in 10:25 下午 2021/4/22
 */
public class AnnotationDependencyInjectDemo {

    @Bean
    public Person femalePerson(){
        return new Person(1,"idea2");
    }

    public static void main(String[] args) {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.register(AnnotationDependencyInjectDemo.class);
        annotationConfigApplicationContext.refresh();
        PersonHolder personHolder = annotationConfigApplicationContext.getBean(PersonHolder.class);
        System.out.println(personHolder);
        annotationConfigApplicationContext.close();
    }

    /**
     * 自动会进行bean的注入
     *
     * @param femalePerson
     * @return
     */
    @Bean
    public PersonHolder personHolder(Person femalePerson){
        return new PersonHolder(femalePerson);
    }
}
